define([

    //  Dependancy scripts
    // ---------------------------    
    'backbone',

    //  App scripts
    // ---------------------------    
    'app/views/day',
    'app/collections/days',
    'app/global'

], function(Backbone, DayView, DayCollection, appNamespace) 
{
    'use strict';

    var Days = Backbone.View.extend(
    {   
        id          : "view-template", 
        collection  : new DayCollection,

        initialize : function() 
        {
            appNamespace.Vent.on('four-days', this.changeURL, this);
            appNamespace.Vent.on('ten-days', this.changeURL, this);
        },
        
        fetchData   : function() 
        {
            var _this = this;

            this.collection.fetch(
            {
                success : function(collection, responce, options) 
                {   
                    _this.render();
                },

                error : function(collection, responce, options) 
                {
                    console.log("This is an error");
                }
            });
        },

        render : function() 
        {
            this.collection.each(this.addOne, this);
            return this;
        },

        addOne : function(dayModel) 
        {
            var dayView  = new DayView(
            {
                model : dayModel
            });

            this.$el.append(dayView.render().el);
        },        

        changeURL : function(options) 
        {
            this.$el.empty();
            this.collection.changeURL(options.forcats);
            this.fetchData();
        }
    })

    return Days
});